package com.jzr.board.ui.fragment.main

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import com.jzr.board.R
import com.jzr.board.base.BaseFragment
import com.jzr.board.bean.NurseSchedulBean
import com.jzr.board.presenter.contract.NurseSchedulFragmentContract
import com.jzr.board.presenter.impl.NurseSchedulFragmentImpl
import com.jzr.board.ui.adapter.NurseSchedulApadter
import com.jzr.board.utils.PreferUtil
import kotlinx.android.synthetic.main.fragment_nurs_schedul.*

class NurseSchedulFragment:BaseFragment(), NurseSchedulFragmentContract.View {

    companion object {
        fun newInstance(): NurseSchedulFragment? {
            return NurseSchedulFragment()
        }
    }

    private val mPresenter = NurseSchedulFragmentImpl()

    private var mAdapterDay : NurseSchedulApadter?=null
    private var mAdapterNight :NurseSchedulApadter?=null
    private var mAdapterAtNight :NurseSchedulApadter?=null
    private var mAdapterRecess :NurseSchedulApadter?=null

    override fun getLayoutResId(): Int {
        return R.layout.fragment_nurs_schedul
    }

    override fun attachView() {
        mPresenter.attachView(this)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mPresenter.getTodayPlan(activity,"deptCode", PreferUtil.getInstance().deptCode)
    }

    override fun getTodayPlanSuccess(data: NurseSchedulBean?) {
          for((index,item )in data?.data?.withIndex()!!){
              when(index){
                  0->{
                      tvName1.text = item.name1
                      mAdapterDay = NurseSchedulApadter(item.staffList)
                      rvDay.layoutManager = GridLayoutManager(activity, 5)
                      rvDay.adapter = mAdapterDay
                  }
                  1->{
                      tvName2.text = item.name1
                      mAdapterNight = NurseSchedulApadter(item.staffList)
                      rvNight.layoutManager = GridLayoutManager(activity, 5)
                      rvNight.adapter = mAdapterNight
                  }
                  2->{
                      tvName3.text = item.name1
                      mAdapterAtNight = NurseSchedulApadter(item.staffList)
                      rvAtNight.layoutManager = GridLayoutManager(activity, 5)
                      rvAtNight.adapter = mAdapterAtNight
                  }
                  3->{
                      tvName4.text = item.name1
                      mAdapterRecess = NurseSchedulApadter(item.staffList)
                      rvRecess.layoutManager = GridLayoutManager(activity, 5)
                      rvRecess.adapter = mAdapterRecess
                  }
              }
          }
    }

    override fun showError(message: String?) {

    }

}